import Mock from 'mockjs';

import {v4 as uuidv4} from 'uuid';

import categoryBooksData from "/public/json/data.json"; // 默认书籍数据
import hotBooksData from "/public/json/hot.json"; // 热搜书籍数据
import newBooksData from "/public/json/newbook.json"; // 新书榜
import novelBooksData from "/public/json/novel.json"; // 小说榜
import topData from "/public/json/top200.json";  //top200总榜
import masterpieceData from "/public/json/masterpiece.json";  //top200总榜



// 模拟返回飙升榜书籍数据
Mock.mock('/api/category-books', 'get', () => {
    const updatedBooks = categoryBooksData.map((book) => {
        return {
            id: uuidv4(),
            title: book.title,
            author: book.author.trim(),
            readingCount: book.readingCount,
            recommendationRate: book.recommendationRate,
            description: book.description,
            cover: book.img || `https://picsum.photos/120/160?random=${Mock.Random.integer(1, 100)}`
        };
    });

    return {
        code: 200,
        message: '请求成功',
        data: updatedBooks
    };
});

// 模拟返回热搜书籍数据
Mock.mock('/api/hot-books', 'get', () => {
    const updatedHotBooks = hotBooksData.map((book) => {
        return {
            id: uuidv4(),
            title: book.title,
            author: book.author.trim(),
            readingCount: book.readingCount,
            recommendationRate: book.recommendationRate,
            description: book.description,
            cover: book.img || `https://picsum.photos/120/160?random=${Mock.Random.integer(1, 100)}`
        };
    });

    return {
        code: 200,
        message: '请求成功',
        data: updatedHotBooks
    };
});


// 模拟返回新书书籍数据
Mock.mock('/api/new-books', 'get', () => {
    const updatedNewBooks = newBooksData.map((book) => {
        return {
            id: uuidv4(),
            title: book.title,
            author: book.author.trim(),
            readingCount: book.readingCount,
            recommendationRate: book.recommendationRate,
            description: book.description,
            cover: book.img || `https://picsum.photos/120/160?random=${Mock.Random.integer(1, 100)}`
        };
    });

    return {
        code: 200,
        message: '请求成功',
        data: updatedNewBooks
    };
});

// 模拟返回小说榜单书籍数据
Mock.mock('/api/novel-books', 'get', () => {
    const updatedBooks = novelBooksData.map((book) => {
        return {
            id: uuidv4(),
            title: book.title,
            author: book.author.trim(),
            readingCount: book.readingCount,
            recommendationRate: book.recommendationRate,
            description: book.description,
            cover: book.img || `https://picsum.photos/120/160?random=${Mock.Random.integer(1, 100)}`
        };
    });

    return {
        code: 200,
        message: '请求成功',
        data: updatedBooks
    };
});

// // 模拟返回小说榜单书籍数据
// Mock.mock('/api/novel-books', 'get', () => {
//     const updatedBooks = novelBooksData.map((book) => {
//         return {
//             id: uuidv4(),
//             title: book.title,
//             author: book.author.trim(),
//             readingCount: book.readingCount,
//             recommendationRate: book.recommendationRate,
//             description: book.description,
//             cover: book.img || `https://picsum.photos/120/160?random=${Mock.Random.integer(1, 100)}`
//         };
//     });
//
//     return {
//         code: 200,
//         message: '请求成功',
//         data: updatedBooks
//     };
// });

// top200总榜
Mock.mock('/api/top200', 'get', () => {
    const updatedBooks = topData.map((book) => {
        return {
            id: uuidv4(),
            title: book.title,
            author: book.author.trim(),
            readingCount: book.readingCount,
            recommendationRate: book.recommendationRate,
            description: book.description,
            cover: book.img || `https://picsum.photos/120/160?random=${Mock.Random.integer(1, 100)}`
        };
    });

    return {
        code: 200,
        message: '请求成功',
        data: updatedBooks
    };
});

// 神作榜
Mock.mock('/api/masterpiece-books', 'get', () => {
    const updatedBooks = masterpieceData.map((book) => {
        return {
            id: uuidv4(),
            title: book.title,
            author: book.author.trim(),
            readingCount: book.readingCount,
            recommendationRate: book.recommendationRate,
            description: book.description,
            cover: book.img || `https://picsum.photos/120/160?random=${Mock.Random.integer(1, 100)}`
        };
    });

    return {
        code: 200,
        message: '请求成功',
        data: updatedBooks
    };
});

// 模拟菜单数据
Mock.mock('/api/menu-items', 'get', () => {
    const menuNames = [
        {name: "TOP50飙升榜", apiUrl: "/api/category-books"},
        {name: "TOP50热搜榜", apiUrl: "/api/hot-books"},
        {name: "TOP50新书榜", apiUrl: "/api/new-books"},
        {name: "TOP50小说榜", apiUrl: "/api/novel-books"},
        {name: "TOP200总榜", apiUrl: "/api/top200"},
        {name: "神作榜", apiUrl: "/api/masterpiece-books"},
        {name: "神作/潜力榜", apiUrl: "/api/potential-books"},
        {name: "精品小说", apiUrl: "/api/premium-books"},
        {name: "历史", apiUrl: "/api/history-books"},
        {name: "文学", apiUrl: "/api/literature-books"},
        {name: "艺术", apiUrl: "/api/art-books"},
        {name: "人物传记", apiUrl: "/api/biography-books"},
        {name: "哲学宗教", apiUrl: "/api/philosophy-books"},
        {name: "计算机", apiUrl: "/api/computer-books"},
        {name: "心理", apiUrl: "/api/psychology-books"},
        {name: "社会文化", apiUrl: "/api/sociology-books"},
        {name: "个人成长", apiUrl: "/api/self-growth-books"},
        {name: "经济理财", apiUrl: "/api/economics-books"},
        {name: "政治军事", apiUrl: "/api/political-books"},
        {name: "童书", apiUrl: "/api/kids-books"},
        {name: "教育学习", apiUrl: "/api/education-books"},
        {name: "科学技术", apiUrl: "/api/science-books"},
        {name: "生活百科", apiUrl: "/api/life-books"},
        {name: "期刊杂志", apiUrl: "/api/journal-books"},
        {name: "原版书", apiUrl: "/api/original-books"},
        {name: "医学健康", apiUrl: "/api/health-books"},
        {name: "男生小说", apiUrl: "/api/male-novel-books"},
        {name: "女生小说", apiUrl: "/api/female-novel-books"}
    ];

    const menuItems = menuNames.map((item, index) => ({
        id: index + 1,
        name: item.name, // 菜单项名称
        index: `menu-${index + 1}`, // 菜单项的 index
        apiUrl: item.apiUrl // 新增的 apiUrl 字段
    }));

    return {code: 200, data: menuItems};
});
